export function object2Query(obj) {
  let query = '';
  Object.keys(obj).forEach((key) => {
    query += `&${key}=${encodeURIComponent(obj[key])}`;
  });
  if (query.length > 1) {
    query = query.substr(1);
  }
  return query;
}

export function getQueryParam(param, url = window.location.href) {
  const name = param.replace(/[[\]]/g, '\\$&');
  const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`);
  const results = regex.exec(url);
  if (!results) return null;
  if (!results[2]) return '';
  return decodeURIComponent(results[2].replace(/\+/g, ''));
}

